import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/db";

export const POST = async (request: NextRequest, response: any) => {
  //解析传过来的body参数
  const body = await request.json();
  console.log("111", body);
  // 构建查询条件
  const where = {
    username: body.username,
    password: body.password,
  };
  const users = await prisma.user.findMany({
    where,
  });
  console.log("users", users);

  if (users.length > 0) {
    return NextResponse.json(
      {
        success: true,
        errorMessage: "登陆成功",
      },
      {
        headers: {
          "Set-Cookie": "admin-token=123;Path=/",
        },
      }
    );
  } else {
    return NextResponse.json({
      success: false,
      errorMessage: "账号或者密码错误！",
    });
  }
};
